import json
import random
from pathlib import Path
from  dataclasses import dataclass
from typing import  NamedTuple,Dict,Literal,Tuple,cast

class PunchProfile(NamedTuple):
    choices: int
    threshold: int
    hit_damage: int
    block_damage: int
    pre_msg: str
    hit_msg: str
    blocked_msg: str
    knockout_possible: bool = False

    def is_hit(self):
        return random.randint(1,self.choices) <= self.threshold

class Player:
    name: str
    best: int
    weakness: int
    is_computer: bool
    punch_profiles:Dict[Literal[1, 2, 3, 4], PunchProfile]
    damage: int = 0
    score: int = 0

    def get_punch_choice(self)->Literal [1,2,3,4]:
        if self.is_computer:
            return random.randint(1,4)
        punch = -1
        while punch not in [1,2,3,4]:
            print(f"{self.name}的招数是？")
            punch = int(input())
        return punch

KNOCKOUT_THRESHOLE =40

KNOCKOUT_COLD = "{loser}被击晕了无法继续进行比赛，胜利属于{winner}"


def get_vulnerability():
    print("敌方的弱点为：")
    return int(input())

def get_opponent_stats() ->Tuple[int,int]:
    opponent_best = 0
    opponent_weakness = 0
    while opponent_best==opponent_weakness:
        opponent_best = random.randint(1,4)
        opponent_weakness = random.randint(1,4)

    return opponent_best,opponent_weakness

def read_punch_profiles(filepath: Path):
    with open(filepath, encoding='utf-8') as f:
        punch_profiles_dict = json.load(f)
    return {
        cast(Literal[1,2,3,4],int(key)):PunchProfile(**value)
        for key,value in punch_profiles_dict.items()
    }

def main() ->None:
    print("")
    print("")
    print("")
    print("")

    print("")

    print("")
    player_name = input()

    print("")
    print("")
    player_best = int(input)
    player_weakness = get_vulnerability()
    player=Player(
        name = player_name,
        best = play_best,
        weakness = play_weakness,
        is_computer=False,
        punch_profiles=read_punch_profiles(
            Path(__file__).parent/"player-profile.json"
        ),
    )

    opponent_best , oppnent_weakness = get_opponent_stats()
    oppnent = Player(
        name=oppnent_name,
        best=opponent_best,
        weakness=oppnent_weakness,
        is_computer=True,
        punch_profiles=read_punch_profiles(
            Path(__file__).parent/"opponent-profile.json"
        ),
    )

    print(player)
    print(opponent)
